import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        api: "modern-compiler" // or 'modern'
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)), // 确保路径正确
    }
  },
  server: {
    proxy: {
      "/dev-api": {
        target: "http://127.0.0.1:19090/system", // 确保服务在这个地址上运行
        changeOrigin: true, // 建议加上这个配置，以防出现跨域问题
        rewrite: (p) => p.replace(/^\/dev-api/, ""),
      },
    },
  },
})
